package com.qf.service.impl;



import com.qf.dao.BooksBorrowDao;
import com.qf.dao.MessageDao;
import com.qf.dao.impl.BooksBorrowDaoImpl;
import com.qf.dao.impl.MessageDaoImpl;
import com.qf.entity.BorrowCard;
import com.qf.entity.Message;
import com.qf.service.MessageService;

import java.sql.SQLException;

public class MessageServiceImpl implements MessageService {
    private MessageDao messageDao = new MessageDaoImpl();
    private BooksBorrowDao booksBorrowDao = new BooksBorrowDaoImpl();
    @Override
    public int addMessage(Message message, Integer uid) {
        int num = -1;
        try {
            BorrowCard borrowCard = booksBorrowDao.selectBorrowCardByUid(uid);
            if(borrowCard!=null){
                message.setCard_id(borrowCard.getBcid());
                num = messageDao.addMessage(message);
            }else {
                return -1;
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return num>0?num:0;
    }
}
